<?php
class NewsController extends Zend_Controller_Action{
	protected $_model = null;
	public function init(){
		$this->_model = new Application_Model_DbTable_News();
		$this->view->layout()->placeholders = array(
				'slider'=>array('status'=>false,'content'=>''),
				'search'=>array('status'=>false,'content'=>'')
		
		);
	}
	
	public function indexAction(){
		$filters = array();
		
		//từ khóa
		$keyword = $this->_request->getParam('keyword','');
		$filters['keyword']=$keyword;
		$this->view->keyword = $keyword;
		
		//phân loại
		$category = $this->_request->getParam('category',0);
		$filters['category']=$category;
		$this->view->category = $category;
		
		//status
		$filters['status']=1;
		
		// sắp xếp | order
		$order = $this->_request->getParam('order',"");
		if($order!=""){
			list($orderBy,$orderType) = explode('-', $order);
		}else{
			$orderBy=null;
			$orderType=null;
		}
		
		
		//get item count per page
		$icpp = $this->_request->getParam('icpp',12);
		
		//get current page number
		$currentPage = $this->_request->getParam('page',1);
		
		$list = $this->_model->getList($filters,$orderType,$orderBy);
		
		// pagination
		$paginator = Zend_Paginator::factory($list);
		$paginator->setCurrentPageNumber($currentPage);
		$paginator->setItemCountPerPage($icpp);
		$paginator->setPageRange(5);
		
		//assign to view
		$this->view->paginator=$paginator;
		//$this->_helper->viewRenderer->setNoRender(true);
	}
	
	public function detailAction(){
		$id = $this->_request->getParam('id');
		$row = $this->_model->find($id)->current();
		if($row){
			$this->view->row = $row;
		}
	}
}